﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FinalWork
{
    public partial class FormEdit : Form
    {

        private readonly manuServices services = new manuServices();
        /// <summary>
        /// 当前记录的id
        /// </summary>
        private Guid id;
        public FormEdit()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 从上级窗体导入id
        /// </summary>
        /// <param name="id"></param>
        public FormEdit(Guid id)
        {
            InitializeComponent();
            var item = services.GetById(id);
            if (item != null)
            {
                textBox1.Text = item.菜名;
                textBox2.Text = item.份数;
                textBox3.Text = item.价格;

                this.id = id;
            }
        }
        private void FormEdit_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            manuEditModel model = new manuEditModel()
            {
                Id = this.id,
                菜名 = textBox1.Text,
                份数 = textBox2.Text,
                价格 = textBox3.Text,

            };
            services.Edit(model);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}
